var app = getApp();
var baseUrl = app.globalData.host;
// 在需要使用的js文件中，导入js
var util = require('../../../../utils/utils.js');
Component({
  data: {
      formData :[],
      lists:[{}],
      oprSiteAttr:["请选择","自有","租赁","其他"],
      oprSiteIndex:0,
      rentDeliverIs:false,
      othOprmngSiteAttrIs:false,
      lbseasonFlagAttr:["请选择","是","否"],
      lbseasonFlagIndex:0,
      cashflowQtAcctypeAttr:["请选择","个人结算账户","公司结算账户"],
  },
  methods: {
    
    addList: function(){
      var  lists = this.data.lists;
      var newData = {};
      lists.push(newData);//实质是添加lists数组内容，使for循环多一次
      this.setData({
        lists: lists,
      })
    },
    //删除
    delList: function () {
      let lists = this.data.lists;
      let formDatas = this.data.formData;
      if(lists.length !== 1)
      {
        lists.pop();      //实质是删除lists数组内容，使for循环少一次
        if(formDatas.length>1)
        {
          formDatas.pop();
        }
        this.setData({
          lists: lists,
          formData: formDatas,
        })
      }
    },

    formInputChange(e) {
      let index = e.target.dataset.field
      let count = index.charAt(index.length-1);
      let name = index.substring(0,index.length-1)
      this.setData({
          [`formData[${[count]}].${name}`]: e.detail.value
      })
    },
    bindBusinessOprSite:function(e){
      console.log('picker country 发生选择改变，携带值为', e.detail.value);
      let index = e.target.dataset.field
      let count = index.charAt(index.length-1);
      let name = index.substring(0,index.length-1)
      let rentDeliverIs = false;
      let othOprmngSiteAttrIs = false;
      if(e.detail.value === '2'){
        rentDeliverIs = true;
      }
      if(e.detail.value === '3'){
        othOprmngSiteAttrIs = true;
      }
      this.setData({
          [`formData[${[count]}].${name}`]: e.detail.value,
          [`formData[${[count]}].rentDeliverIs`]:rentDeliverIs,
          [`formData[${[count]}].othOprmngSiteAttrIs`]: othOprmngSiteAttrIs,
      })
    },
    bindBusinesslbseasonFlag:function(e){
      console.log('picker country 发生选择改变，携带值为', e.detail.value);
      let index = e.target.dataset.field
      let count = index.charAt(index.length-1);
      let name = index.substring(0,index.length-1)
      let lbseasonFlagIs = false;
      if(e.detail.value === '1'){
        lbseasonFlagIs = true;
      }
      this.setData({
        [`formData[${[count]}].${name}`]: e.detail.value,
        [`formData[${[count]}].lbseasonFlagIs`]: lbseasonFlagIs,
      })
    },
    bindBusinesscashflowQtAcc:function(e){
      console.log('picker country 发生选择改变，携带值为', e.detail.value);
      let index = e.target.dataset.field
      let count = index.charAt(index.length-1);
      let name = index.substring(0,index.length-1)
      this.setData({
        [`formData[${[count]}].${name}`]: e.detail.value,
      })
    },
    bindbeginDateChange: function (e) {
      let index = e.target.dataset.field
      let count = index.charAt(index.length-1);
      this.setData({
        [`formData[${[count]}].beginDate`]: e.detail.value,
      })
    },
    bindendDateChange: function (e) {
      let index = e.target.dataset.field
      let count = index.charAt(index.length-1);
      this.setData({
        endDate: e.detail.value,
        endDates:e.detail.value,
        [`formData[${[count]}].endDate`]: e.detail.value,
      })
    },
    bindOtherAreaBlur:function(e){
      let index = e.target.dataset.field
      let count = index.charAt(index.length-1);
      let name = index.substring(0,index.length-1)
      this.setData({
        [`formData[${[count]}].${name}`]: e.detail.value,
      })
    },
    submitForm: function() {
      // this.setData({
      //   disabled:true
      // });
      var data = this.data.formData;
      console.info(data);
     },

    onLoad: function(option) {
      var time = util.formatTime(new Date());
      console.info(time);
      var that = this;
      that.setData({
        custId:option.custIad,
        [`formData.custId`]: option.custId,
        time:time,
        endDates:time,
      });
      var data = that.data.formData;
      //查询数据回显
    },
  },
});